package com.cli.springboot_netty;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.UnsupportedEncodingException;

@SpringBootApplication
public class SpringbootNettyApplication {

    public static void main(String[] args) throws UnsupportedEncodingException {
        SpringApplication.run(SpringbootNettyApplication.class, args);

        stringTest();
    }

    public static void stringTest() throws UnsupportedEncodingException {
        String str = "测";
        char x = '测';
        byte[] byteStr = str.getBytes();
        byte[] byteChar = charToByte(x);
        System.out.println("byteStr ：" + byteStr.length); // byteStr ：3
        System.out.println("byteChar：" + byteChar.length); // byteChar：2

        System.out.println(new String(byteChar,"UTF-16"));
    }

    // 通过移位获取char类型的byte数组
    public static byte[] charToByte(char c) {
        byte[] b = new byte[2];
        b[0] = (byte) ((c & 0xFF00) >> 8);
        b[1] = (byte) (c & 0xFF);
        return b;
    }

}
